package top.bingoz.wanandroid.base

import android.arch.lifecycle.Lifecycle
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.trello.lifecycle2.android.lifecycle.AndroidLifecycle
import com.trello.rxlifecycle2.LifecycleProvider
import top.bingoz.wanandroid.contract.Contract
import top.bingoz.wanandroid.toast

/**
 * @author su
 * @date 2018/8/2
 * @description
 */
abstract class BaseFragment : Fragment(), Contract.View {

    protected val provider: LifecycleProvider<Lifecycle.Event> = AndroidLifecycle.createLifecycleProvider(this)


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return LayoutInflater.from(container?.context).inflate(getLayoutId(), container, false)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initialize()
    }

    open protected fun initialize() {
    }

    abstract fun getLayoutId(): Int


    override fun showloading() {
    }

    override fun dismissloading() {

    }

    override fun showError(msg: String?) {
        context?.toast(msg)
    }

}